/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 4/4/21.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class DurationUtils {
  static String fromatMil(
    int seconds, {
    bool day = false,
    bool hour = false,
  }) {
    Duration flagDuration = Duration(seconds: seconds);
    //距离的 天 、小时、分钟、秒 (总数)
    //如 1天 、24小时、24*60秒
    int inDays = flagDuration.inDays;
    int inHours = flagDuration.inHours;
    int inMinutes = flagDuration.inMinutes;
    int inSeconds = flagDuration.inSeconds;

    //计算时间间隔 如 01天12小时33分钟45秒
    String twoDigitDyays = twoDigits(inDays.remainder(365) as int);
    String twoDigitHours = twoDigits(inHours.remainder(24) as int);
    String twoDigitMinutes = twoDigits(inMinutes.remainder(60) as int);
    String twoDigitSeconds = twoDigits(inSeconds.remainder(60) as int);

    if (day) {
      return "$twoDigitDyays天$twoDigitHours小时$twoDigitMinutes分钟$twoDigitSeconds秒";
    } else if (hour) {
      return "$twoDigitHours小时$twoDigitMinutes分钟$twoDigitSeconds秒";
    } else {
      return "$twoDigitMinutes分钟$twoDigitSeconds秒";
    }
  }

  static String fromatMil2(
    int seconds, {
    bool day = false,
    bool hour = false,
  }) {
    Duration flagDuration = Duration(seconds: seconds);
    //距离的 天 、小时、分钟、秒 (总数)
    //如 1天 、24小时、24*60秒
    int inDays = flagDuration.inDays;
    int inHours = flagDuration.inHours;
    int inMinutes = flagDuration.inMinutes;
    int inSeconds = flagDuration.inSeconds;

    //计算时间间隔 如 01天12小时33分钟45秒
    String twoDigitDyays = twoDigits(inDays.remainder(365) as int);
    String twoDigitHours = twoDigits(inHours.remainder(24) as int);
    String twoDigitMinutes = twoDigits(inMinutes.remainder(60) as int);
    String twoDigitSeconds = twoDigits(inSeconds.remainder(60) as int);

    if (day) {
      return "$twoDigitDyays:$twoDigitHours:$twoDigitMinutes:$twoDigitSeconds";
    } else if (hour) {
      return "$twoDigitHours:$twoDigitMinutes:$twoDigitSeconds";
    } else {
      return "$twoDigitMinutes:$twoDigitSeconds";
    }
  }

  //转双位输出
  static String twoDigits(int n) {
    if (n >= 10) return "$n";
    return "0$n";
  }
}
